<template>
  <lb-layout
    v-loading="$store.getters.loading"
    element-loading-text="拼命加载中"
    element-loading-spinner="el-icon-loading"
    element-loading-background="#a19f9fb0;"
    :paddBottom="5"
  >
    <el-button size="small" @click="goBack"> 返回 </el-button>
    <el-button type="warning" size="small" plain @click="exportDeal"
      >导出</el-button
    >

    <el-tabs
      ref="tabs"
      v-model="activeName"
      class="text-tabs TTB-no-gutter TTB-gutter"
      @tab-click="handlerTabschange"
    >
      <el-tab-pane label="综1表" name="basic1" ref="basic1"></el-tab-pane>
      <el-tab-pane label="综2表" name="basic2" ref="basic2"></el-tab-pane>
      <el-tab-pane label="综3表" name="basic3" ref="basic3"></el-tab-pane>
      <el-tab-pane label="综4表" name="basic4" ref="basic4"></el-tab-pane>
    </el-tabs>
    <component :is="activeName" :ref="activeName"></component>
  </lb-layout>
</template>

  <script>
import { exportBasicExcel, exportExcel } from "@/utils/xlsx";
import { getInfo } from "@/api/login";
import basic1 from "@/views/work/accounts/components/basic1.vue";
import basic2 from "@/views/work/accounts/components/basic2.vue";
import basic3 from "@/views/work/accounts/components/basic3.vue";
import basic4 from "@/views/work/accounts/components/basic4.vue";
export default {
  components: {
    basic1,
    basic2,
    basic3,
    basic4,
  },
  props: {},
  data() {
    return {
      deptLevel: null,
      activeName: "basic1",
      disabledFlage: false,
      isCorrect: false,
      apsForm: {
        formRef: "searchform",
        labelWidth: "auto",
        formData: {},
        formConfig: {
          formAttr: {
            inline: true,
            size: "small",
          },
          properties: {
            companyName: {
              label: "单位名称：",
              typeName: "aps-des",
            },
            fillType: {
              label: "填报类型：",
              typeName: "aps-des",
            },
            yearmonth: {
              label: "时间段：",
              typeName: "aps-des",
            },
          },
        },
      },
      buttonName: "",
    };
  },
  created() {
    this.getDeptLevel();
    setTimeout(() => {
      this.searchFromSet();
    }, 200);
  },
  mounted() {},
  methods: {
    exportDeal() {
      let user = this.$store.state.user;
      let deptName = user?.deptName ?? "未知单位名称";
      let infos = [];
      infos.push(deptName ?? "");
      infos.push(this.$route.query?.unitLeader ?? "");
      infos.push(this.$route.query?.statisticLeader ?? "");
      infos.push(this.$route.query?.createTime ?? "");
      if (this.$route.query.year && this.$route.query.month) {
        infos.push(this.$route.query?.year + this.$route.query?.month);
      } else {
        infos.push("");
      }
      infos.push("报");
      let fileName =
        this.activeName == "basic1"
          ? "公共机构能源资源消费统计分级汇总情况"
          : this.activeName == "basic2"
          ? "公共机构能源资源消费统计分类汇总情况"
          : this.activeName == "basic3"
          ? "公共机构数据中心机房能源消费统计汇总情况"
          : "公共机构采暖能源资源消费统计汇总情况";
      let index =
        this.activeName == "basic1"
          ? 5
          : this.activeName == "basic2"
          ? 6
          : this.activeName == "basic3"
          ? 7
          : 8;
      let cols = [{ wpx: 240 }];
      let ref = this.$refs[this.activeName].$refs.excelTable;
      //exportExcel(ref, fileName, cols);
      exportBasicExcel(ref, fileName, cols, index, infos);
    },
    async getDeptLevel() {
      const res = await getInfo();
      this.deptLevel = res.user.deptLevel;
    },
    searchFromSet() {
      let query = this.$route.query;
    },
    handlerTabschange() {
      const name = this.$refs.tabs.value;
      if (this.activeName === name) {
        return false;
      }
    },
    goBack() {
      // this.$router.push({
      //   path: "/work/standbook",
      // });
      this.$router.go(-1);
      // let activeMenu = this.$route.meta.activeMenu; // 激活的菜单也是返回的菜单
      // this.$router.push({
      //   path: activeMenu,
      // });
    },
    handlerSaveandReport() {
      this.$refs.basic2.parentTelltodo();
    },
  },
};
</script>

  <style lang="scss" scoped>
.text-tabs {
  margin-left: -40px;
  margin-bottom: 20px;
}
.top-button-area {
  display: flex;
  justify-content: flex-end;
}
</style>
